import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/monitor',
    component: Layout,
    redirect: '/monitor/monitor-list',
    name: 'monitor',
    meta: { title: '监控管理', icon: 'el-icon-video-camera' },
    children: [
      {
        path: 'monitor-list',
        name: 'monitor-list',
        component: () => import('@/views/monitor/monitor-list'),
        meta: { title: '监控列表', icon: 'el-icon-video-camera' }
      },
      {
        path: 'monitor-realtime',
        name: 'monitor-realtime',
        hidden: true,
        component: () => import('@/views/monitor/monitor-watch'),
        meta: { title: '实时监控', icon: 'el-icon-video-camera' }
      },
      {
        path: 'monitor-playback',
        name: 'monitor-playback',
        hidden: true,
        component: () => import('@/views/monitor/monitor-watch'),
        meta: { title: '监控回放', icon: 'el-icon-s-data' }
      },
    ]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/user-list',
    name: 'user',
    meta: { title: '人员管理', icon: 'peoples' },
    children: [
      {
        path: 'user-list',
        name: 'user-list',
        component: () => import('@/views/user/user-list'),
        meta: { title: '人员列表', icon: 'el-icon-s-custom' }
      },
      {
        path: 'attendance',
        name: 'attendance',
        component: () => import('@/views/user/attendance'),
        meta: { title: '考勤情况', icon: 'el-icon-document-checked' }
      },
      {
        path: 'violation',
        name: 'violation',
        component: () => import('@/views/user/user-violation'),
        meta: { title: '违规情况', icon: 'el-icon-warning-outline' }
      }
    ]
  },

  {
    path: '/machine',
    component: Layout,
    redirect: '/machine/machine-list',
    name: 'machine',
    meta: { title: '施工设备管理', icon: 'el-icon-coin' },
    children: [
      {
        path: 'machine-list',
        name: 'machine-list',
        component: () => import('@/views/machine/machine-list'),
        meta: { title: '设备管理', icon: 'el-icon-set-up' }
      },
      {
        path: 'machine_track',
        name: 'machine_track',
        component: () => import('@/views/machine/machine_track'),
        meta: { title: '设备追踪', icon: 'el-icon-location-information' }
      },
      {
        path: 'machine_situation',
        name: 'machine_situation',
        component: () => import('@/views/machine/machine_situation'),
        meta: { title: '设备故障处理', icon: 'el-icon-circle-close' }
      }
    ]
  },

  {
    path: '/environment',
    component: Layout,
    redirect: '/environment/environment-list',
    name: 'machine',
    meta: { title: '环境类型', icon: 'el-icon-pie-chart' },
    children: [
      {
        path: 'environment-list',
        name: 'environment-list',
        component: () => import('@/views/environment/environment-list'),
        meta: { title: '环境监测看板', icon: 'el-icon-pie-chart' }
      },
      {
        path: 'environment-Details',
        name: 'environment-Details',
        hidden: true,
        component: () => import('@/views/environment/environment-details'),
        meta: { title: '详细数据', icon: 'el-icon-tickets' }
      },
    ]
  },

  {
    path: '/train',
    component: Layout,
    redirect: '/train/video-list',
    meta: { title: '在线培训', icon: 'el-icon-pie-chart' },
    children: [
      {
        path: 'video-list',
        name: 'video-list',
        component: () => import('@/views/train/video-list'),
        meta: { title: '施工安全培训', icon: 'el-icon-s-help' }
      },
      {
        path: 'video-play',
        name: 'video-play',
        hidden: true,
        component: () => import('@/views/monitor/monitor-watch'),
        meta: { title: '在线视频', icon: 'el-icon-s-data' }
      }
    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
